<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8"%>
<%@taglib prefix="mvc" uri="http://www.springframework.org/tags/form" %>
<%@taglib prefix="fmt" uri="http://www.springframework.org/tags" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title>修改客户信息</title>
    <link rel="stylesheet" type="text/css" href="../../lib/pagination/style/pagination.css"/>
    <link rel="stylesheet" type="text/css" href="../../css/base.css"/>
    <link rel="stylesheet" type="text/css" href="../../css/news/center.css"/>
    <link rel="stylesheet" href="/lib/laydate/need/laydate.css">
    <link rel="stylesheet" type="text/css" href="/css/commonTheme/${sessionScope.InterfaceModel}/commonTheme.css"/>
    <link rel="stylesheet" href="../../lib/ueditor/formdesign/bootstrap/css/bootstrap.min.css">
    <link rel="stylesheet" href="../../css/crm/gapp_bar.css?20191021" />
    <link rel="stylesheet" href="../../css/crm/gapp_tab.css?20191021" />
    <link rel="stylesheet" href="../../css/crm/laydate.css" />
    <link rel="stylesheet" href="/lib/pagination/style/pagination.css">
    <script type="text/javascript" src="../../js/news/jquery-1.9.1.js"></script>
    <script src="/lib/laydate/laydate.js"></script>
    <script type="text/javascript" src="/js/base/tablePage.js"></script>
    <script src="../../js/news/page.js"></script>
    <script src="../../lib/laydate/laydate.js"></script>
    <script src="../../js/base/base.js" type="text/javascript" charset="utf-8"></script>
    <script src="../../lib/pagination/js/jquery.pagination.min.js" type="text/javascript" charset="utf-8"></script>
    <script src="../../lib/layer/layer.js?20201106"></script>
    <script src="/lib/pagination/js/jquery.pagination.min.js" type="text/javascript" charset="utf-8"></script>
    <style>
        body {
            font-family: 微软雅黑;
            font-size: 14px;
            line-height: 20px;
            color: rgb(51, 51, 51);
        }
        h1, h2, h3, h4, h5, h6 {
            font-family: 微软雅黑;
            color: inherit;
            text-rendering: optimizeLegibility;
            margin: 5px 0px;
        }
        h3 {
            display: block;
            -webkit-margin-before: 1em;
            -webkit-margin-after: 1em;
            -webkit-margin-start: 0px;
            -webkit-margin-end: 0px;
        }
        p {
            display: block;
            -webkit-margin-before: 1em;
            -webkit-margin-after: 1em;
            -webkit-margin-start: 0px;
            -webkit-margin-end: 0px;
        }
        .contain{
            margin: 0px -250px;
        }
        .edit_out{
            margin:-11px -228px;
        }
        .head_p{
            padding: 22px 0px;
            margin: -40px 0px 0px 0px;
        }
        #follow{
            margin-top: -20px;
        }
        #follow span{
            padding: 1px 0px;
        }
        .follow_text input{
            background: none;
            border: none;
            width: 125px;
            color: #6b7995;
        }
        select{
            width: 200px;
        }
        .inner{
            width: 200px;
        }
        .linkcard{
            width: 100%;
            border: 1px solid #dcdcdc;
            background: #fff;
            margin-bottom: 20px;
        }
        #add_img{
            margin: 20px 43%;
            background-image:url(../../img/crm/add_img.png);
            height: 28px;
            width: 75px;
            color: white;
            padding:1px 0px 0px 22px;
        }
        tr{
            border: none;
        }
        input{
            margin-left: -4px;
        }
        .state2{
            /*overflow:scroll;*/
            height:100%;
        }
        .state2 .create_new{
            padding-left: 16px;
            width: 96%;
        }
    </style>
    <link rel="stylesheet" type="text/css" href="/css/commonTheme/${sessionScope.InterfaceModel}/commonTheme.css"/>
</head>
<body class="crm_background_img">
<!--head开始-->
<div class="side-bar" style="right: 0px; top: 0px;">
    <span class="close_btn" ></span>
    <button id="delete_data" value="删除" data="4" allow_de="1">
        <span class="delete">X</span>
        <span>删除</span>
    </button>
    <div class="contain">
        <header class="header" style="height: 100px">
            <h3 class="h3"></h3>
            <p class="head_p">创建人：<img onerror="imgerror(this,1)"  src=""/>
                <span class="c_photo"></span>
                <span class="edit_out">
                    <span class="edit_add">＋</span>
                    <button id="edit" >编辑</button>
                </span></p>
            <p class="head_p">创建时间：<span class="c_time"></span></p>
        </header>
        <div class="main" tabindex="5000" style="height: 85%;  outline: none;position: relative;margin-top: 14px">
            <div class="cut-option" style="position: fixed;width: 465px;z-index: 999">
                <ul>
                    <li class="confirm">基本信息</li>
                    <li class="follow">跟进记录</li>
                    <li class="linkman">联系人</li>
                </ul>
            </div>
            <div style="margin-top: 35px;overflow-x: hidden;overflow-y:auto;position: absolute;width: 100%;height: 92%;">
            <form id="ajaxform" action="/customer/updateWorkbench" style="margin-top: 8px">
                <section class="section state1" state=1 style="height: 100%">
                    <div class="section_in">
                        <table class="table" id="basefirm_table">
                            <tr class="basefirm" id="basefirm"><td colspan="2" ><span>|</span>客户信息</td></tr>
                        </table>
                    </div>
                    <div class="section_in" id="linkfirm_div">
                        <table class="table">
                            <tr class="linkfirm" id="linkfirm">
                                <td colspan="2"><span>|</span>联系信息</td>
                            </tr>
                            <tr class="con_head" id="con_head" style="height: 118px;"></tr>
                        </table>
                    </div>
                </section>
            </form>
            <form id="ajaxforms" action="/customer/updateWorkbench" style="margin-top: -12px">
                <section class="section state2" state=2 style="display: none;">
                    <div class="create_new">
                        <p><span>|</span>新建跟进记录</p>
                        <div>
                            &nbsp;&nbsp;<span>联系方式:</span>
                            <select class="linktype" name="followType">
                            </select>
                            <div class="send">
                                <button type="button" value="发表" class="btn btn-info btn-small" id="create_record">发表</button>
                            </div>
                            <textarea id="text" style="height:100px;" placeholder="请描述跟进情况和目前存在的问题..." wrap="physical" name="followSituation"></textarea>
                        </div>
                    </div>
                    <div class="genjin commom_div">
                    </div>
                    <div class="right" style="float: right;margin-right: 2%;">
                        <!-- 分页按钮-->
                        <div class="M-box3" id="dbgz_page"></div>
                    </div>
                </section>
            </form>
                <section class="section" id="select_linkman"  style="display: none;">
                    <div class="section_in" style="margin: 0">
                        <table class="table">
                            <tr class="basefirm">
                                <td colspan="2"><span>|</span>联系人</td>
                            </tr>
                        </table>
                    </div>
                </section>
                <div>
                    <button id="add_img" type="button">添加</button>
                </div>
            <form id="ajax_add">
                <section class="section state3" id="add" state=3 style="display: none;">
                    <div class="section_in" id="new_linkman">
                        <table class="table">
                            <tr class="basefirm">
                                <td colspan="2"><span>|</span>新建联系人</td>
                            </tr>
                            <tr>
                                <td>姓名<input class="inner" type="text" name="linkmanName"/></td>
                                <td>性别
                                    <select id="sex" name="sex" class="inner">
                                        <option value="0">请选择性别</option>
                                        <option value ="1" >男</option>
                                        <option value ="2" >女</option>
                                    </select>
                                </td>
                            </tr>
                            <tr>
                                <td>部门<input class="inner" type="text" name="department"/></td>
                                <td>职务<input class="inner" type="text" name="job"/></td>
                            </tr>
                            <tr>
                                <td>电话<input class="inner" type="telephone" name="mobile" maxlength="11"/></td>
                                <td>微信<input class="inner" type="text" name="wechat" maxlength="20"/></td>
                            </tr>
                            <tr>
                                <td>QQ号<input class="inner" type="text" name="qq" maxlength="10"/></td>
                                <td>邮箱<input class="inner" name="email" type="email"/></td>
                            </tr>
                            <tr>
                                <td>备注<input class="inner" type="text" name="remark"/></td>
                                <td><button type="button" class="create_linkman" onclick="create_linkman()" value="保存">保存</button></td>
                            </tr>
                        </table>
                    </div>
                    <div class="link commom_div"></div>
                </section>
            </form>
            <form id="ajax_upd">
                <section class="section state3" id="update" state=3 style="display: none;">
                    <div class="section_in" id="update_linkman">
                        <table class="table">
                            <tr class="basefirm">
                                <td colspan="2"><span>|</span>编辑联系人</td>
                            </tr>
                            <tr>
                                <td>姓名<input class="inner" type="text" name="linkmanName"/></td>
                                <td>性别
                                    <select id="update_sex" name="sex" class="inner">
                                        <option value="0">请选择性别</option>
                                        <option value ="1" >男</option>
                                        <option value ="2" >女</option>
                                    </select>
                                </td>
                            </tr>
                            <tr>
                                <td>部门<input class="inner" type="text" name="department"/></td>
                                <td>职务<input class="inner" type="text" name="job"/></td>
                            </tr>
                            <tr>
                                <td>电话<input class="inner" type="telephone" name="mobile" maxlength="11"/></td>
                                <td>微信<input class="inner" type="text" name="wechat" maxlength="20"/></td>
                            </tr>
                            <tr>
                                <td>QQ号<input class="inner" type="text" name="qq" maxlength="10" id="qq"/></td>
                                <td>邮箱<input class="inner" name="email" type="email" id="email"/></td>
                            </tr>
                            <tr>
                                <td>备注<input class="inner" type="text" name="remark"/></td>
                                <td><button type="button" class="create_linkman" id="create_updman" name="linkmanId" value="">保存</button></td>
                            </tr>
                        </table>
                    </div>
                    <div class="link commom_div"></div>
                </section>
            </form>
            </div>
        </div>
    </div>
</div>
</div>
</body>
<script>
    var getRequestObj=$.GetRequest();
    var followTypeData = {};
    $(function () {
        var type = $.GetRequest().type;
        var allType = $.GetRequest().allType;
        //我的客户权限
        if(type==0){
            $('.edit_out').css('display','block');
            $('#delete_data').css('display','block');
        }else if(type==1){
            $('.edit_out').css('display','block');
            $('#delete_data').css('display','none');
        }else if(type==2){
            $('.edit_out').css('display','block');
            $('#delete_data').css('display','block');
        }else if(type==3){
            $('.edit_out').css('display','block');
            $('#delete_data').css('display','none');
        }else if(type==4){
            $('.edit_out').css('display','none');
            $('#delete_data').css('display','none');
        }
        //下属客户权限
        if(allType==0){
            $('.edit_out').css('display','block');
            $('#delete_data').css('display','block');
        }else if(allType==1){
            $('.edit_out').css('display','none');
            $('#delete_data').css('display','none');
        }else if(allType==2){
            $('.edit_out').css('display','none');
            $('#delete_data').css('display','block');
        }else if(allType==3){
            $('#delete_data').css('display','none');
            $('.edit_out').css('display','block');
        }else if(allType==4){
            $('#delete_data').css('display','none');
            $('.edit_out').css('display','none');
        }
        linkman_up();
        follow_up ();
        $("#add_img").css("display","none");
    })
    //编辑基本信息
    function edit_data(){
        var t=$("#edit").text();
        if(t=="编辑"){
            $(".confirm").css("border-bottom","2px solid #19bd9b").siblings().css("border-bottom","0");
            $(".state1").css("display","");
            $("#edit").html("保存");
            $("#delete_data span:eq(1)").html("取消");
            $(".state1 .table tr td").find('input').addClass('border').attr('readonly',false);
            $(".table tr td").find("input").eq(3).attr("type","hidden");
            $(".table tr td").find("input").eq(1).attr("type","hidden");
            $(".table tr td").find("input").eq(7).attr("type","hidden");
            $(".table tr td").find("input").eq(5).attr("type","hidden");
//            $(".table tr td").find("input").slice(9,13).attr("type","hidden");
            $(".state1  .table  tr td .choose_s").css('display','block');
            $("#next_gen").addClass("laydate-icon");
        }else{
            var email=$('[name="email"]').val();
            $("#delete_data span:eq(1)").html("删除");
            var bo = /^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/.test(email);
            if (email != ''&&bo == false){
                layer.msg('邮箱格式错误 ！',{icon:2});
                return;
            }
            $("#edit").html("编辑");
            $(".state1 .table tr td").find('input').removeClass('border').attr('readonly',true);
            $(".table tr td").find("input").eq(3).attr("type","");
            $(".table tr td").find("input").eq(1).attr("type","");
            $(".table tr td").find("input").eq(7).attr("type","");
            $(".table tr td").find("input").eq(5).attr("type","");
            $([name="fromText"]).attr("type","");
//            $(".table tr td").find("input").slice(9,13).attr("type","");
            $(".choose_s").css('display','none');

            $("#next_gen").removeClass("laydate-icon");
        }
    }

    //页面数据加载基本信息，跟进记录，联系人
    function init(){
        $.ajax({
            data:{
                customerId:getRequestObj.customerId
            },
            dataType:'json',
            type:"get",
            url:'/customer/selectCustomerById',
            async:false,
            success:function(json){
                if(json.flag){
                    var data=json.object;
//                创建人
                    $(".c_photo").html(data.creator);
                    $('.head_p img').attr('src', function () {
                        if(json.object.avatar != 0&&json.object.avatar != 1&&json.object.avatar != ''){
                            return '/img/user/'+json.object.avatar;
                        }
                        if(data.sex == 0){
                            return '/img/user/boy.png';
                        }
                        else if(data.sex == 1){
                            return '/img/user/girl.png';
                        }

                    }());
//                创建时间
                    $(".c_time").html(data.createdTime);
//                客户名称
                    if(data.customerName.length>=16){
                        $(".header .h3").html('<a title='+data.customerName+' style="color: #fff;text-decoration:none;cursor:default">'+data.customerName.replace(/(.{16})(.*)/g,'$1...')+'</a>');
                    }else{
                        $(".header .h3").html(data.customerName)
                    }

                    //基本信息
                    var sex;
                    if(json.object.sex==1){
                        var sex='男'
                    }else{
                        var sex='女'
                    }
                    if (data.qq==undefined) {
                        data.qq==null;
                    }
                    if (data.mobile==undefined) {
                        data.mobile==null;
                    }
                    if (data.wechat==undefined) {
                        data.wechat==null;
                    }
                    if (data.email==undefined) {
                        data.email==null;
                    }
                    if (data.job==undefined) {
                        data.job==null;
                    }
                    if (data.scale==undefined) {
                        data.scale==null;
                    }
                    if (data.address==undefined) {
                        data.address==null;
                    }
                    if (data.customerManager==undefined) {
                        data.customerManager==null;
                    }
                    if (data.annualSales==undefined) {
                        data.annualSales==null;
                    }
                    if (data.website==undefined) {
                        data.website==null;
                    }
                    if (data.zipCode==undefined) {
                        data.zipCode==null;
                    }
                    var tr1='<tr class="basefirm" id="basefirm"><td colspan="2"><span>|</span>客户信息</td></tr>'+
                        '<tr>' + '<td>客户编号<span class="inner" id="prospective_number" >'+data.customerNo+'</span></td>' +
                        '<td>客户名称<input class="inner" title='+data.customerName+' value="'+function () {
                            if(data.customerName.length>=13){
                                return data.customerName.replace(/(.{13})(.*)/g,'$1...')
                            }else{
                                return data.customerName
                            }
                        }()+'" readonly="true" name="customerName"/></td>' +
                        '</tr>' +
                        '<tr>' +
                        '<td >客户级别<input class="inner" value="" readonly="true" name="levelText" /><input class="inner" value="'+data.customerLevel+'" readonly="true" class="customerLevel" type="hidden" style="display: none"></td>' +
                        '<td >客户状态<input class="inner" value="" readonly="true" name="statusText"/><input class="inner" value="'+data.customerStatus+'" readonly="true" class="customerStatus" type="hidden" style="display: none"/>' +
                        '</td>' +
                        '</tr>' +
                        '<tr>' +
                        '<td >客户来源<input class="inner" value="" readonly="true" name="fromText"/><input class="inner" value="'+data.customerFrom +'" readonly="true" class="customerFrom" type="hidden"/></td>' +
                        '<td> 客户行业<input class="inner" value="" readonly="true" name="industryText"/><input class="inner" value="'+data.customerIndustry+'" readonly="true" class="customerIndustry" type="hidden"/></td>' +
                        '</tr>'+
                        '<tr>' +
                        '<td>客户经理<input class="inner" value="'+data.customerManager+'" readonly="true" name="customerManager"/></td>' +
                        '<td>公司规模<input class="inner" value="'+data.scale+'"readonly="true" name="scale"/></td>' +
                        '</tr>'+
                        '<tr>' +
                        '<td>年销售额<input maxlength="10" class="inner" value="'+data.annualSales+'" readonly="true" name="annualSales"/></td>' +
                        '<td>公司地址<input class="inner" value="'+data.address+'" readonly="true" name="address"/></td>' +
                        '</tr>'+
                        '<tr>' +
                        '<td>公司网址<input class="inner" value="'+data.website+'" readonly="true" name="website"/></td>' +
                        '<td>邮编<input class="inner" value="'+data.zipCode+'" readonly="true" name="zipCode"/>' +
                        '</tr>'+
                        '</tr>';
                    $('#basefirm_table').html(tr1);
                    $(".table tr").find("td").eq(4).find('select').remove();

                    //客户状态
                    var statusName = data.customerStatus;
                    $.ajax({
                        url: "/customer/selectByStatus",
                        type:'get',
                        dataType:"JSON",
                        success:function(data){
                            var str='<select class="choose_s choose_s0" id="customerStatus">';
                            for (var i=0;i<data.object.length;i++){
                                str += '<option value="'+data.object[i].codeNo+'">'+data.object[i].codeName+'</option>'
                            }
                            str+='</select>'
                            $(".table tr").find("td").eq(4).append(str);
                            $('.choose_s0').html(str);
                            $('.choose_s0').val(statusName);
                            $('.customerStatus').val($('.choose_s0 option:selected').text());
                            $('[name="statusText"]').val($('.choose_s0 option:selected').text());
                        }
                    })

                    //客户来源
                    var formName = data.customerFrom;
                    $.ajax({
                        url: "/customer/selectBySource",
                        type:'get',
                        dataType:"JSON",
                        success:function(data){
                            var str='<select class="choose_s choose_s2" id="customerFrom">';
                            for (var i=0;i<data.obj.length;i++){
                                str += '<option value="'+data.obj[i].codeNo+'">'+data.obj[i].codeName+'</option>'
                            }
                            str+='</select>'
                            $(".table tr").find("td").eq(5).append(str);
                            $('.choose_s2').html(str);
                            $('.choose_s2').val(formName);
                            $('.customerFrom').val($('.choose_s2 option:selected').text());
                            $('[name="fromText"]').val($('.choose_s2 option:selected').text());
                        }
                    })

                    //客户级别
                    var customerName=data.customerLevel
                    $.ajax({
                        url: "/customer/selectByLevel",
                        type:'get',
                        dataType:"JSON",
                        success:function(data){
                            var str='<select class="choose_s choose_s1" id="customerLevel">';
                            for (var i=0;i<data.object.length;i++){
                                str += '<option value="'+data.object[i].codeNo+'">'+data.object[i].codeName+'</option>'
                            }
                            str+='</select>'
                            $(".table tr").find("td").eq(3).append(str);
                            $('.choose_s1').html(str);
                            $('.choose_s1').val(customerName);
                            $('.customerLevel').val($('.choose_s1 option:selected').text());
                            $('[name="levelText"]').val($('.choose_s1 option:selected').text());
//                        alert($('.choose_s5 option:selected').text())
                        }
                    })

                    //客户行业
                    var industryName = data.customerIndustry
                    $.ajax({
                        url: "/customer/selectByIndustry",
                        type:'get',
                        dataType:"JSON",
                        success:function(data){
                            var str='<select class="choose_s choose_s5" id="customerIndustry">';
                            for (var i=0;i<data.obj.length;i++){
                                str += '<option value="'+data.obj[i].codeNo+'">'+data.obj[i].codeName+'</option>'
                            }
                            str+='</select>'
                            $(".table tr").find("td").eq(6).append(str);
                            $('.choose_s5').html(str);
                            $('.choose_s5').val(industryName);
                            $('.customerIndustry').val($('.choose_s5 option:selected').text());
                            $('[name="industryText"]').val($('.choose_s5 option:selected').text());
                        }
                    })

                    //首选联系方式
                    var firsteee =  data.firstContact
                    $.ajax({
                        url: "/customer/selectByType",
                        type:'get',
                        dataType:"JSON",
                        success:function(data){
                            if(data.flag){
                                var str=""
                                for (var i=0;i<data.obj.length;i++){
                                    str += '<option value="'+data.obj[i].codeNo+'">'+data.obj[i].codeName+'</option>'
                                    followTypeData[data.obj[i].codeNo] = data.obj[i].codeName
                                }
                                $('[name="followType"]').html(str);
                                $('.choose_s4').html(str);
                                $('.choose_s4').val(firsteee);
                                $('[name="firstTest"]').val($('.choose_s4 option:selected').text());
                                $('.firstContact').val($('.choose_s4').val());
                            }
                        }
                    })
                }
            }
        });
    }
    init();
    linkman();
    //基本信息回显当前用户第一个联系人
    function linkman() {
        $.ajax({
            data:{
                customerId:getRequestObj.customerId
            },
            dataType:'json',
            type:"get",
            url:'/linkMan/selectCustomerById',
            async:false,
            success:function (s) {
                if (s.flag==true) {
                    $('#linkfirm_div').css('display','')
                    var tr2='';
                    var sex = '';
                    if (s.object.sex == 1) {
                        sex = '男'
                    } else {
                        sex = '女'
                    }
                    tr2 = '<td><img onerror="imgerror(this,1)" src="'+function () {
//                                        if(data[i].users.avater != 0&&data[i].users.avater != 1&&data[i].users.avater != ''){
//                                            return '/img/user/'+data[i].users.avater;
//                                        }
                            if(s.object.sex == 1){
                                return '/img/user/boy.png';
                            }
                            else if(s.object.sex == 2){
                                return '/img/user/girl.png';
                            }
                        }()+'" alt="" style="width: 40px;height: 40px">' +
                        '<p id="follow" style="margin: 10px 0px 0px 10px">' +
                        '<span class="follow_name">' + s.object.linkmanName + '</span>' +
                        '<span class="follow_text">性别：<input value="' + sex + '" style="width: 136px;margin-top: -2px;" /></span>' +
                        '<span class="follow_text">部门：<input value="' + s.object.department + '" style="margin-top: -2px;"><br/></span>' +
                        '<span class="follow_text">职务：<input value="' + s.object.job + '" style="width: 136px;margin-top: -2px;"/></span>' +
                        '<span class="follow_text">电话：<input value="' + s.object.mobile + '" style="margin-top: -2px;"/></span><br/>' +
                        '<span class="follow_text">微信：<input value="' + s.object.wechat + '" style="width: 136px;margin-top: -2px;"/></span>' +
                        '<span class="follow_text">Q&nbsp;Q：<input value="' + s.object.qq + '" style="margin-top: -2px;"/></span><br/>' +
                        '<span class="follow_text">邮箱：<input value="' + s.object.email + '" style="width: 136px;margin-top: -2px;"/></span>' +
                        '<span class="follow_text">备注：<input value="' + s.object.remark + '" style="margin-top: -2px;"/></span></p></td>'
                    $('#con_head').html(tr2);
                    //删除当前联系人
                }else{
                    $('#linkfirm_div').css('display','none')
                }
            }
        })
    }
    //新建联系人
    function create_linkman(){
        var email=$('[name="email"]').val();
        var bo= /^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/.test(email);
        var qq=$('[name="qq"]').val();
        var qqPattern = /^[1-9][0-9]{4,11}$/.test(qq)
        if(qq != ''&&qqPattern == false){
            layer.msg('QQ格式 ！',{icon:2});
        }else if(email != ''&&bo == false){
            layer.msg('邮箱格式错误 ！',{icon:2});
        }else {
            $.ajax({
                data: $('#ajax_add').serialize() + '&customerId=' + getRequestObj.customerId,
                dataType: 'json',
                type: "post",
                url: '/linkMan/addLinkMan',
                success: function (data) {
                    if (data.flag) {
                        layer.msg('保存成功！', {icon: 1}, function () {
                            $("#new_linkman").css("display", "none");
                            $("#select_linkman").css("display", "block");
                            $("#add_img").css("display","block");
                            linkman_up();
                        });
                        /*添加成功*/
                    } else {
                        layer.msg('保存失败！', {icon: 2});
                        /*添加失败*/
                    }
                },
                error: function (data) {
                    layer.msg('保存失败！', {icon: 2});
                    /*添加失败*/
                }
            });
        }
    }
    //联系人数据回显
    function linkman_up() {
        $.ajax({
            url:'/linkMan/selectBylinkman',
            data:{
                customerId:getRequestObj.customerId
            },
            type: 'get',
            dataType: 'json',
            success:function (s) {
                if (s.flag) {
                    var tr3='';
                    for(var i=0;i<s.object.length;i++) {
                        var sex = '';
                        if (s.object[i].sex == 1) {
                            sex = '男'
                        } else {
                            sex = '女'
                        }
                        tr3 += '<div class="con_head"  style="display:table;background-color: white;margin-bottom: 20px;border: 1px solid rgb(220, 220, 220);"><img onerror="imgerror(this,1)" src="'+function () {
//                                if(s.object[i].avater != 0&&s.object[i].avater != 1&&s.object[i].avater != ''){
//                                    return '/img/user/'+data[i].users.avater;
//                                }
                                if(s.object[i].sex == 1){
                                    return '/img/user/boy.png';
                                }
                                else if(s.object[i].sex == 2){
                                    return '/img/user/girl.png';
                                }
                            }()+'" alt="">' +
                            '<p id="follow" style="margin: 10px 0px 0px 10px">' +
                            '<span class="follow_name" >' + s.object[i].linkmanName + '</span>' +
                            '<span class="follow_text">性别：<input value="' + sex + '" style="width: 145px"/></span>' +
                            '<span class="follow_text">部门：<input value="' + s.object[i].department + '"/><br/></span>' +
                            '<span class="follow_text">职务：<input value="' + s.object[i].job + '" style="width: 145px"/></span>' +
                            '<span class="follow_text">电话：<input value="' + s.object[i].mobile + '"/></span><br/>' +
                            '<span class="follow_text">微信：<input value="' + s.object[i].wechat + '" style="width: 145px"/></span>' +
                            '<span class="follow_text"> QQ：<input value="' + s.object[i].qq + '"/></span><br/>' +
                            '<span class="follow_text">邮箱：<input value="' + s.object[i].email + '" style="width: 145px"/></span>' +
                            '<span class="follow_text">备注：<input value="' + s.object[i].remark + '"/></span></p>' +
                            '<span class="icon edit" title="编辑"  linkmanId="' + s.object[i].linkmanId + '"><i></i><a></a></span>' +
                            '<span class="icon linkman_del" title="删除"  linkmanId="' + s.object[i].linkmanId + '" ><i></i><a></a></span>' +
                            '</div>'
                    }
                    $('#select_linkman').html(tr3);
                    //删除当前联系人
                    $('.linkman_del').click(function () {
                        var linkmanId=$(this).attr('linkmanId')
                        layer.confirm(qued,{
                            btn: [sure,cancel], //按钮
                            title:'确定删除？'
                        }, function(){
                            $.ajax({
                                type:'post',
                                url:'/linkMan/deleteLinkMan',
                                dataType:'json',
                                data:{'linkmanId':linkmanId},
                                success: function (json) {
                                    //第三方扩展皮肤
                                    layer.msg('<fmt:message code="workflow.th.delsucess" />', {icon: 6});
                                    $("#add_img").css("display","block");
                                    linkman_up();
                                }
                            })
                        }, function () {
                            layer.closeAll();
                        })
                    })
                    //编辑当前联系人
                    $('.edit').click(function () {
                        var linkmanId=$(this).attr('linkmanId')
                        //点编辑按钮时跳回编辑页面
                        $("#update").css("display","");
                        $("#add_img").css("display","none");
                        $('#select_linkman').css("display","none");
                        //联系人编辑-回显数据
                        $.ajax({
                            url:'/linkMan/selectByPrimaryKey',
                            data:{'linkmanId':linkmanId},
                            type: 'get',
                            dataType: 'json',
                            success:function (json) {
                                if (json.flag) {
                                    $('[name="linkmanName"]').val(json.object.linkmanName);
                                    $('[name="job"]').val(json.object.job);
                                    $('[name="department"]').val(json.object.department);
                                    $('[name="mobile"]').val(json.object.mobile);
                                    $('[name="email"]').val(json.object.email);
                                    $('[name="wechat"]').val(json.object.wechat);
                                    $('[name="qq"]').val(json.object.qq);
                                    $('[name="linkmanId"]').val(json.object.linkmanId);
                                    if (json.object.sex == 1) {
                                        $("#update_sex option[value='1']").attr("selected", "selected");
                                    } else {
                                        $("#update_sex option[value='2']").attr("selected", "selected");
                                    }
                                }
                            }
                        })
                        $('#create_updman').click(function () {
                            var linkmanId=$(this).val()
                            var email=$('#email').val();
                            var bo= /^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/.test(email);
                            var qq=$('#qq').val();
                            var qqPattern = /^[1-9][0-9]{4,11}$/.test(qq)
                            if(qq != ''&&qqPattern == false){
                                layer.msg('QQ格式 ！',{icon:2});
                            }else if(email != ''&&bo == false){
                                layer.msg('邮箱格式错误 ！',{icon:2});
                            }else {
                                $.ajax({
                                    dataType: 'json',
                                    type: "post",
                                    url: '/linkMan/updateLinkMan',
                                    data: $('#ajax_upd').serialize() + '&linkmanId=' + linkmanId,
                                    success: function (data) {
                                        if (data.flag) {
                                            $.layerMsg({content: '编辑成功', icon: 1}, function () {
                                                $("#update").css("display", "none");
                                                $("#select_linkman").css("display", "block");
                                                $("#add_img").css("display","block");
                                                linkman_up();
                                            })
                                        } else {
                                            layer.msg('编辑失败！', {icon: 2});
                                            /*添加失败*/
                                        }
                                    },
                                    error: function (data) {
                                        layer.msg('编辑失败！', {icon: 2});
                                        /*添加失败*/
                                    }
                                });
                            }
                        })
                    })
                    if(s.object.length==0){
                        tr3 = '<div class="section_in empty" style="width: 446px;text-align: center;height: 200px">' +
                            '<img src="/img/main_img/shouyekong.png" style="width:auto;margin:0 39%;margin-top:40px;">' +
                            '<span style="color:#666;margin: 0 auto;">暂无联系人</span></div>';
                        $('#select_linkman').append(tr3);
                    }
                }else{
                    tr3 = '<div class="section_in empty" style="width: 446px;text-align: center;height: 200px">' +
                        '<img src="/img/main_img/shouyekong.png" style="width:auto;margin:0 39%;margin-top:40px;">' +
                        '<span style="color:#666;margin: 0 auto;">暂无联系人</span></div>';
                    $('#select_linkman').append(tr3);
                }
            }
        })
    }
    //跟进新增
    $('#add_img').click(function () {
        $("#add").css("display","");
        $("#add_img").css("display","none");
        $("#select_linkman").css("display","none");
        $('#new_linkman').css('display','block');
        $('#new_linkman .table input').val("");
        $('#new_linkman .table select').val(0);
    })
    function follow_up () {
        var ajaxPage = {
            data :{
                customerId: getRequestObj.customerId,
                page: 1,//当前处于第几页
                pageSize: 15,//一页显示几条
                useFlag: true
            },
            page: function () {
                var me=this;

                $.ajax({
                    dataType: 'json',
                    type: "get",
                    url: '/customer/findAllFollow',
                    data:me.data,
                    success: function (s) {
                        if (s.flag) {
                            var div = '';
                            for (var i = 0; i < s.obj.length; i++) {
                                div += '<div class="section_in linkcard" >' +
                                    '<span class="icon del" title="删除"  followId="' + s.obj[i].followId + '"><i></i><a>删除</a></span>' +
                                    '<div class="con_head"  style="display:table">' +
                                    '<p id="follow">' +
                                    '<img onerror="imgerror(this,1)" src="' + function () {
                                if(s.obj[i].avatar != 0&&s.obj[i].avatar != 1&&s.obj[i].avatar != ''){
                                    return '/img/user/'+s.obj[i].avatar;
                                }
                                        if (s.obj[i].sex == 1) {
                                            return '/img/user/boy.png';
                                        }
                                        else if (s.obj[i].sex == 2) {
                                            return '/img/user/girl.png';
                                        }
                                    }() + '" alt="">' +
                                    '<span class="follow_name" >&nbsp;&nbsp;' + s.obj[i].creator + '</span>' +
                                    '<span class="follow_time" >&nbsp;&nbsp;联系时间：' + s.obj[i].followTime + '</span>' +
                                    '<span class="follow_time" style="margin-left: 49px;">跟进方式：' + selFollowType(s.obj[i].followType) + '</span>' +
                                   function () {
                                    if(s.obj[i].address==undefined){
                                        return ''
                                    }else{
                                        return  '<span class="address"  style="margin-left: 49px;">跟进地址：' + s.obj[i].address + '</span>'
                                    }
                                   }()+
                                   function () {
                                        if(s.obj[i].feedback==undefined){
                                            return ''
                                        }else{
                                            return '<span class="feedback" style="margin-left: 49px;display: block;width: 400px;">需求反馈：' +  s.obj[i].feedback + '</span>'
                                        }
                                   }()+
                                    '<span class="followSituation" style="margin-left: 49px;display: block;width: 400px;">跟进情况：' + s.obj[i].followSituation+ '</span>' +
                                    '</p>' +

                                    '</div></div>'

                            }
                            $('.genjin').html(div);
                            me.pageTwo(s.totleNum,me.data.pageSize,me.data.page);
                            $('.jump-ipt').height('30px')
                            $(".create_new #text").val("");
                            //跟进- 根据id删除该条跟进信息
                            //ajax 根据followId 删除数据
                            $('.del').click(function () {
                                var followId = $(this).attr('followId');
                                var documentThis = $(this);
                                layer.confirm(qued, {
                                    btn: [sure, cancel], //按钮
                                    title: '确定删除？'
                                }, function () {
                                    $.ajax({
                                        type: 'post',
                                        url: '/customer/deleteFollow',
                                        dataType: 'json',
                                        data: {'followId': followId},
                                        success: function (json) {
                                            //第三方扩展皮肤
//                                            console.log(documentThis.parent().parent().attr('class'))
                                            layer.msg('<fmt:message code="workflow.th.delsucess" />', {icon: 6});
                                            follow_up()
//                                            documentThis.parent().parent().css("display", "none")
                                        }
                                    })
                                }, function () {
                                    layer.closeAll();
                                })
                            })
                        }
                    },
                })
            },
            pageTwo: function (totalData, pageSize, indexs) {
                var mes = this;
                $('#dbgz_page').pagination({
                    totalData: totalData,
                    showData: pageSize,
                    jump: true,
                    coping: true,
                    homePage: '',
                    endPage: '',
                    current: indexs || 1,
                    callback: function (index) {
                        mes.data.page = index.getCurrent();
                        mes.page();
                    }
                });
            }
        }
        ajaxPage.page();
    }
    //跟进
    $('#create_record').click(function () {
        $.ajax({
            url: '/customer/insertFollow',
            type: 'post',
            dataType: 'json',
            data: $('#ajaxforms').serialize() + '&customerId=' + getRequestObj.customerId + '&firstContact=' + $(".linktype option:selected").val().toString(),
            success: function (data) {
                if (data.flag) {
                    layer.msg('跟进成功！', {icon: 1}, function () {
                        follow_up ()
                    });
                    /*添加成功*/
                } else {
                    layer.msg('跟进失败！', {icon: 2});
                    /*添加失败*/
                }
            },
            error: function (data) {
                layer.msg('跟进失败！', {icon: 2});
                /*添加失败*/
            }
        })
    })
    function selFollowType(typeId){
        if(typeId!=undefined&&typeId!=''){
            if(followTypeData[typeId]!=undefined)
                return followTypeData[typeId];
        }
        return '';

    }

    //点击切换基本信息/跟进记录/联系人
    $('.confirm').click(function () {
        linkman();
        $(".confirm").css("border-bottom","2px solid #19bd9b").siblings().css("border-bottom","0");
        $(".state2").css("display","none");
        $(".state3").css("display","none");
        $(".state1").css("display","");
        $("#select_linkman").css("display","none");
        $("#add_img").css("display","none");
    })
    $('.follow').click(function () {
        $(".follow").css("border-bottom","2px solid #19bd9b").siblings().css("border-bottom","0");
        $(".state1").css("display","none");
        $(".state3").css("display","none");
        $(".state2").css("display","");
        $("#select_linkman").css("display","none");
        $("#add_img").css("display","none");
    })
    $('.linkman').click(function () {
        $(".linkman").css("border-bottom","2px solid #19bd9b").siblings().css("border-bottom","0");
        $(".state1").css("display","none");
        $(".state2").css("display","none");
        $(".state3").css("display","none");
        $("#select_linkman").css("display","");
        $("#add_img").css("display","");
    })
    //对单个联系人进行修改提交
    $('#edit').on('click',function () {
        $('#ajaxform').find('[name="firstTest"]').val($('.choose_s4 option:selected').text())
        $('#ajaxform').find('[name="firstContact"]').val($('.choose_s4').val())
        var data = $('#ajaxform').serialize()
        edit_data();
        if($('#edit').text()=="编辑") {
            $.ajax({
                dataType: 'json',
                type: "post",
                url: '/customer/updateByPrimaryKeyWithBLOBs',
                data: data + '&customerNo=' + $('#prospective_number').text() + '&customerId=' + getRequestObj.customerId + '&customerLevel=' + $("#customerLevel option:selected").val() + '&customerStatus=' + $("#customerStatus option:selected").val() + '&customerFrom=' + $("#customerFrom option:selected").val() + '&customerIndustry=' + $("#customerIndustry option:selected").val() + '&firstContact=' + $("#firstContact option:selected").val(),
                //                data: data+ '&customerId=' + getRequestObj.customerId,
                success: function (data) {
                    if (data.flag) {
                        $.layerMsg({content: '编辑成功', icon: 1}, function () {
                            location.reload();
                        })

                    } else {
                        layer.msg('编辑失败！', {icon: 2});
                        /*添加失败*/
                    }
                },
                error: function (data) {
                    layer.msg('编辑失败！', {icon: 2});
                    /*添加失败*/
                }
            });
        }
    })
    $('.close_btn').click(function () {
        $("#pop-up",window.parent.document).animate({right:'-600px'},"slow");
    })
    $('.add_btn').click(function () {
        $('#ajaxforms input').removeAttr("disabled");
        $('#ajaxforms select').removeAttr("disabled");
    })

    $('#delete_data').click(function(){
        if($("#delete_data span:eq(1)").html()=='删除'){
            layer.confirm('<fmt:message code="sup.th.Delete" />？', {
                btn: ['<fmt:message code="global.lang.ok" />', '<fmt:message code="depatement.th.quxiao" />'] //按钮
            }, function () {
                //确定删除，调接口
                $.ajax({
                    url: '/customer/deleteCustomer',
                    type: 'post',
                    dataType: 'json',
                    data: {
                        customerId:getRequestObj.customerId
                    },
                    success: function (obj) {
                        //第三方扩展皮肤
                        layer.msg('<fmt:message code="workflow.th.delsucess" />', {icon: 6});
//                    location.reload();
                        $("#pop-up",window.parent.document).animate({right:'-600px'},"slow");
//                    window.location.reload()
                        window.parent.pageObj.init();
                    }
                })
            }, function () {
                layer.closeAll();
            });
        }else{
            $('#edit').html("编辑");
            $("#delete_data span:eq(1)").html("删除");
            init()
        }
    });
</script>

</html>
